﻿Imports NUnit.Framework
Imports PhDir.DAL
Imports System.IO

Namespace UnitTesting.DAL

    <TestFixture()>
    Public Class TestSetupDb

        Private Const DropPhoneDb = "IF DB_ID('PhoneDb') IS NOT NULL DROP DATABASE PhoneDb;"
        Private Const CheckPhoneDb = "SELECT DB_ID('PhoneDb');"
        Private Const CheckUsersTable = "SELECT OBJECT_ID('Users');"

        <Test()>
        Public Sub TestCreatePhoneDbAfterDroppingPhoneDb()
            Dim actualResult As Object = Nothing

            Using dbConnection = New DbConnection(DbContext.MasterContext)
                dbConnection.CommandText = DropPhoneDb
                dbConnection.ExecuteNonQuery()

                SetupDb.InitializeDatabase()

                dbConnection.CommandText = CheckPhoneDb
                actualResult = dbConnection.ExecuteScalar()
            End Using

            Assert.NotNull(actualResult)
        End Sub

        <Test()>
        Public Sub TestIfUsersTableExists()
            Dim actualResult As Object = Nothing

            Using dbConnection = New DbConnection(DbContext.PhoneContext)
                SetupDb.InitializeDatabase()

                dbConnection.CommandText = CheckUsersTable
                actualResult = dbConnection.ExecuteScalar()
            End Using

            Assert.NotNull(actualResult)
        End Sub

    End Class

End Namespace
